package com.youdianstar.app.adapter

import android.app.Activity
import android.widget.ImageView
import coil.load
import com.youdianstar.app.R
import com.youdianstar.app.entity.BranchLogo
import com.zhpan.bannerview.BaseBannerAdapter
import com.zhpan.bannerview.BaseViewHolder


/**
 * File: LogoBannerAdapter
 * Author: Administrator Create: 2024/6/18 0018 15:48
 * Changes (from 2024/6/18 0018)
 * --------------------------------------------------
 * description:
 * ---------------------------------------------------
 *
 */
class LogoBannerAdapter(val mContext: Activity) : BaseBannerAdapter<BranchLogo>() {

    override fun bindData(holder: BaseViewHolder<BranchLogo>?, data: BranchLogo?, position: Int, pageSize: Int) {
        val ivLogo = holder?.findViewById<ImageView>(R.id.iv_logo_item)
        val logoDF = R.mipmap.icon_default_logo
        if (getViewType(position) == 1) {
            data?.url?.let { url->
                ivLogo?.load(url) {
                    placeholder(logoDF)
                    error(logoDF)
                }
            }
        }else{
            ivLogo?.setImageResource(logoDF)
        }
    }

    override fun getViewType(position: Int): Int {
        return mList[position].type
    }

    override fun getLayoutId(viewType: Int): Int {
        return R.layout.layout_banner_logo
    }
}